package control;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.KeyStroke;

import view.AbstractContentJPanel;
import view.NotCloseableException;

/**
 * Standardaktion um Tabs zu schliessen
 */
@SuppressWarnings("serial")
public class CloseTabAction extends AbstractAction {
	private AbstractContentJPanel panel;
	
	public CloseTabAction(AbstractContentJPanel contentPanel){
		super("Tab schliessen");
		this.panel = contentPanel;
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));

		setEnabled(panel.isCloseable());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		try {
			panel.tryToClose();
		} catch (NotCloseableException e1) {
			
		}
	}

}
